﻿Imports System.Globalization
Imports System.Runtime.CompilerServices
Public Module ModuleExtentrions
    <Extension()>
    Public Function ConverToDateTime(ByVal src As String, ByVal format As String) As DateTime
        Return DateTime.ParseExact(src, format, Globalization.CultureInfo.InvariantCulture)
    End Function
    <Extension()>
    Public Function ConvertDecimalMoeda(ByVal src As Decimal) As String
        Return src.ToString("c", New CultureInfo("pt-PT"))
    End Function
    <Extension()>
    Public Function ConvertMoedapDecimal(ByVal src As String, sepdecimal As String) As Decimal


        Dim ret As String = ""
        Dim foundSep As Boolean = False
        src.Replace(" ", "").Reverse().ToList().
            ForEach(Function(z)
                        If (sepdecimal.Equals(z) AndAlso Not foundSep) Then
                            ret = z & ret
                            foundSep = True
                        End If
                        If IsNumeric(z) Then
                            ret = z & ret
                        End If
                        Return True
                    End Function)
        Return Convert.ToDecimal(ret)
    End Function
    <Extension()>
    Public Function EqualsIgnoreCase(ByVal src As String, ByVal compare As String)

        If src = compare Then
            Return True
        Else
            If String.IsNullOrEmpty(src) Or String.IsNullOrEmpty(compare) Then
                Return False
            End If
        End If
        If src.ToLower().Equals(compare.ToLower()) Then
            Return True
        End If
        Return False

    End Function
    <Extension()>
    Public Function ContainsIgnoreCase(ByRef src As String, ByVal compare As String)
        If src = compare Then
            Return True
        Else
            If String.IsNullOrEmpty(src) Or String.IsNullOrEmpty(compare) Then
                Return False
            End If
        End If
        If src.ToLower().Contains(compare.ToLower()) Then
            Return True
        End If
        Return False
    End Function
End Module
